#!/bin/sh

update-alternatives --install /opt/bin/scp scp /opt/bin/openssh-scp 80
update-alternatives --install /opt/bin/ssh ssh /opt/bin/openssh-ssh 80

echo

# Check for the SSH1 RSA key
if [ ! -f /opt/etc/openssh/ssh_host_key ]; then
    echo Generating RSA Key...
    /opt/bin/ssh-keygen -t rsa1 -f /opt/etc/openssh/ssh_host_key -C '' -N ''
fi

# Check for the SSH2 RSA key
if [ ! -f /opt/etc/openssh/ssh_host_rsa_key ]; then
    echo Generating RSA Key...
    /opt/bin/ssh-keygen -t rsa -f /opt/etc/openssh/ssh_host_rsa_key -C '' -N ''
fi

# Check for the SSH2 DSA key
if [ ! -f /opt/etc/openssh/ssh_host_dsa_key ]; then
    echo Generating DSA Key...
    /opt/bin/ssh-keygen -t dsa -f /opt/etc/openssh/ssh_host_dsa_key -C '' -N ''
fi
                
if [ ! -d /root -a -w / ];  then
    mkdir /root
fi

# Some devices do not have a nobody user for priviledge separation
if grep -v nobody /etc/passwd > /dev/null ; then
    sed -i -e 's/\#UsePrivilegeSeparation yes/UsePrivilegeSeparation no/' /opt/etc/openssh/sshd_config
fi

echo Fixing permissions on the /tmp directory...
chmod 1777 /tmp

/opt/etc/init.d/S40sshd
